package com.wharf.base.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wharf.base.dao.AdminMapper;
import com.wharf.base.dao.UserInfoMapper;
import com.wharf.base.model.Admin;
import com.wharf.base.model.UserInfo;

@Service
public class UserInfoServiceImp implements  UserInfoService{

	
	@Autowired
	private UserInfoMapper userinfo;
	
	@Autowired
	private AdminMapper adminMapper;
	
	
	//普通用户登录查询
	@Override
	public UserInfo selectByIdandpass(String name, String pass) {
		// TODO Auto-generated method stub
		return userinfo.selectByIdandpass(name, pass);
	}
	//管理员登录返回值状态
	@Override
	public boolean AdminLoginAction(String user,String pass) {
		Admin login = adminMapper.selectByUserAndPass(user, pass);
		if(login == null) {
			return false;
		}else {
			return true;
		}
	}
//注册
	@Override
	public int regist(String infoName, String infoPhone, String infoQq, String infoPass) {
		// TODO Auto-generated method stub
		return userinfo.regist(infoName, infoPhone, infoQq, infoPass);
	}

	// 用户管理
		@Override
		public List<UserInfo> userManagement() {
			List<UserInfo> list = userinfo.selectUserPhone();
			return list;
		}

		// 通过手机号查询用户
		@Override
		public List<UserInfo> searchByPhone(String phone) {
			List<UserInfo> selectByPhone = userinfo.selectByPhone(phone);
			return selectByPhone;
		}

		// 管理员添加新用户
		@Override
		public boolean addUserAction(String infoName, String infoPhone, String infoQq, String infoPass) {
			int add = userinfo.addUserInfo(infoName, infoPhone, infoQq, infoPass);
			if (add != 0) {
				return true;
			} else {
				return false;
			}
		}

		@Override
		public boolean delUserInfo(Integer id) {
			int del = userinfo.deleteUserInfo(id);
			if (del != 0) {
				return true;
			} else {
				return false;
			}
		}
}
